/*
 * @Author: xiaoyangzhao
 * @Date:   2018-04-19 17:21:57
 * @Last Modified by:   xiaoyangzhao
 * @Last Modified time: 2018-08-09 11:24:28
 */

import request from '@/utils/request'
import { route_origins, route_path_get } from '@/api/routes'

// const route_origins = 'http://skyapi.zhichengcredit.com/'
// const route_path_get = ''
// 1.客户注册
// http://erp.bjqujiao.com/supplier/register
// 2.获取验证码图片
// http://erp.bjqujiao.com/captcha

/**
{
    "verifyCode": "1234",
    "customer": {
        "supplier": "姓名",
        "accountNumber": "密码",
        "sex": "男",
        "contacts": "职业",
        "brth": "出生年",
        "advanceIn": 186,
        "allNeedGet": 96.5,
        "phonenum": "手机号",
        "address": "邮寄地址",
        "email": "邮箱",
        "description": "身体健康状况"
    }
}
 */
/**
 * [registry 注册接口]
 * @param  {String} supplier        [姓名]
 * @param  {String} accountNumber   [密码]
 * @param  {String} sex             [性别]
 * @param  {String} contacts        [职业]
 * @param  {String} brth            [出生年]
 * @param  {String} advanceIn       [身高]
 * @param  {String} allNeedGet      [体重]
 * @param  {String} phonenum        [手机号]
 * @param  {String} address         [邮寄地址]
 * @param  {String} email           [邮箱]
 * @param  {String} description     [身体健康状况]
 * @param  {String} verifyCode      [图形验证码]
 * @return {Function}               [异步接口方法]
 */
export function registry(params) {
    return request({
        url: route_origins + route_path_get + 'register',
        method: 'post',
        headers: {
            'Content-Type': 'application/json;charset=UTF-8'
        },
        transformRequest: request._origin.transformRequest,
        data: params
    })
}

/**
 * [overdueLogin 登录携带ic和ui]
 * @param  {String} username  [用户名称]
 * @param  {String} password  [密码]
 * @param  {String} imageCode [图形验证码]
 * @return {Function}         [异步接口方法]
 */
export function overdueLogin(params) {
    return request({
        url: route_origins + route_path_get + 'validateLogin',
        method: 'get',
        params
    })
}

/**
 * [login 登录]
 * @param  {String} username  [用户名称]
 * @param  {String} password  [密码]
 * @param  {String} imageCode [图形验证码]
 * @return {Function}         [异步接口方法]
 */
export function login(username, password, imageCode) {
    return request({
        // url: route_origins + route_path_get + 'login',
        url: route_origins + route_path_get + 'login',
        method: 'post',
        data: {
            username,
            password,
            imageCode,
            ajax: 'XMLHttpRequest'
        }
    })
}

/**
 * [imgCaptcha 图形验证码]
 * @param  {Object} param     [description]
 * @return {Function}         [异步接口方法]
 */
export function imgCaptcha(param) {
    return request({
        // url: 'http://echo-star-dev4.zhichengcredit.com/jcaptcha?' + Date.now(),
        url: route_origins + route_path_get + 'jcaptcha?' + Date.now(),
        method: 'get',
        responseType: 'stream',
        param
    })
}

/**
 * [getInfo 获取用户信息]
 * @param  {Array} token  [用户角色口令]
 * @return {Function}     [异步接口方法]
 */
export function getInfo(token) {
    return request({
        url: route_origins + route_path_get + 'user/info',
        method: 'get',
        params: {
            token,
            ajax: 'XMLHttpRequest'
        }
    })
}

/**
 * [logout 登出]
 * @return {Function}     [异步接口方法]
 */
export function logout() {
    return request({
        url: route_origins + route_path_get + 'logout',
        method: 'get'
    })
}

/**
 * [userModifyPwd 重置密码]
 * @param  {Object} params [旧密码oldPassword/新密码newPassword]
 * @return {Function}      [异步接口方法]
 */
export function userModifyPwd(params) {
    return request({
        url: route_origins + route_path_get + 'user/modifyPwd',
        method: 'post',
        params
    })
}

/**
 * [userResetPwd 重置密码]
 * @param  {Object} params [旧密码oldpassword/新密码newpassword]
 * @return {Function}      [异步接口方法]
 */
export function userResetPwd(params) {
    return request({
        url: route_origins + route_path_get + 'user/resetPwd',
        method: 'post',
        params
    })
}

/**
 * [userTodo 首页 待办事项]
 * @return {Function}     [异步接口方法]
 */
export function userTodo(params) {
    return request({
        url: route_origins + route_path_get + 'user/todo',
        method: 'get',
        params
    })
}

/**
 * [reportCoverHome 首页 覆盖率报表数据]
 * @return {Function}     [异步接口方法]
 */
export function reportCoverHome(params) {
    return request({
        url: route_origins + route_path_get + 'report/cover/query/home',
        method: 'get',
        params
    })
}
